package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Answer;
import cn.wolfcode.luowowo.article.mapper.AnswerMapper;
import cn.wolfcode.luowowo.article.service.IAnswerContentService;
import cn.wolfcode.luowowo.article.service.IAnswerService;
import cn.wolfcode.luowowo.cache.vo.WendaStats;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class AnswerServiceImpl implements IAnswerService {

    @Autowired
    private AnswerMapper answerMapper;

    @Autowired
    private IAnswerContentService answerContentService;

    @Override
    public void insert(Answer answer) {
        answer.setGoldmedal(false);
        answer.setPathfinder(true);
        answer.setViewnum(0);
        answer.setFavornum(0);
        answer.setReleaseTime(new Date());
        answerMapper.insert(answer);
        answer.getAnswerContent().setId(answer.getId());
        answerContentService.insert(answer.getAnswerContent());
    }

    @Override
    public WendaStats selectById(Long answerId) {
        return answerMapper.selectById(answerId);
    }
}
